//Definitions of internal messages

cplusplus {{
#include "IPvXAddress.h"
}}

enum Messages {
	CONFIGURE = 1;
	CONFIGURED = 2;
	DATATIMER = 3;
	TRACKTIMER = 4;
};

message DataTimer {
	kind = DATATIMER;
};

message TrackTimer {
	kind = TRACKTIMER;
};


//Definition of packets
enum PingType {
	PING = 10;
	PONG = 11;
}

enum P2PType {
	PEERREQ = 20;
	PEERLIST = 21;
	PEEREXIT = 22;
	STREAMREQ = 23;
	DATA = 24;
	ADVERTISEMENT = 25;
};

enum MessageSize{
	DATA_B = 1024;
	REQUESTS_B = 1024;
};

//General base class
packet General {
	int type;
	string srcAddr;
	string dstAddr;
}

//Rtt test packets
packet Ping extends General {
	type = PING;
}

packet Pong extends General {
	type = PONG;
}


//Packet generated by P2P applications
packet P2PApp extends General {
	int peerID;
	int streamID;
	int nHops = 0;
	byteLength = REQUESTS_B;
}

//Request a peer list to tracker
packet PeerRequest extends P2PApp{
	int type = PEERREQ;
	int rank;
};

//Packet with a list of peers
packet PeerList extends P2PApp{
	string peerList[];
	int type = PEERLIST;
};

enum ExitCause{
	EXIT_NONE = 0;
	EXIT_LOAD = 1;
	EXIT_GRACE = 2;
	EXIT_UPDATE = 3;
	EXIT_STABLE = 4;
	EXIT_ERROR = 5;
};

//Friendly disconnection or request deny
packet PeerExit extends P2PApp{
	int subStreamID;
	int type = PEEREXIT;
	int cause = EXIT_NONE;
};

//Advertisement sent to tracker to inform the data avaliability
packet Advertisement extends P2PApp {
	int type = ADVERTISEMENT;
	string moduleName;
};

//Request for a substream to a peer
packet StreamReq extends P2PApp{
	int subStreamID;
	int chunk = 0;
	int rank;
	int type = STREAMREQ;
};

//Data packet
packet Data extends P2PApp{
	int subStreamID;
	double timestamp;
	int type = DATA;
};

